package com.yc.boot.train.business;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.boot.common.model.response.Outcome;
import com.yc.boot.sys.business.SysUserBusiness;
import com.yc.boot.sys.model.UserInfo;
import com.yc.boot.train.entity.GradeCommentFeedback;
import com.yc.boot.train.model.find.GradeFeedBack;
import com.yc.boot.train.model.find.GradeManage;
import com.yc.boot.train.model.find.IPageGradeFeedback;
import com.yc.boot.train.model.find.IPageGradeManage;
import com.yc.boot.train.model.update.UpdateGradeFeedback;
import com.yc.boot.train.service.GradeCommentFeedbackService;
import com.yc.boot.train.service.GradeFeedbackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Create with IntelliT IDEA
 *
 * @Author: zhengmingzhe
 * @Date: 2022/01/06/15:33
 * @Description:
 */
@Slf4j
@Service
public class CourseFeedbackBussiness {
    @Resource
    private GradeFeedbackService gradeFeedbackService;

    @Resource
    private SysUserBusiness sysUserBusiness;

    @Resource
    private GradeCommentFeedbackService gradeCommentFeedbackService;
        /*
         * @Description  分页查询分数回馈界面
         * @Param
         * @return
         **/
    public IPage<GradeFeedBack> queryGradeFeedback(IPageGradeFeedback param){
          UserInfo user = sysUserBusiness.getUserInfo();
//        UserInfo user =new UserInfo();
//        user.setId(4L);
        IPage<GradeFeedBack> gradeFeedback = gradeFeedbackService.queryGradeFeedback(new Page<>(param.getCurrent(), param.getSize()),
                new QueryWrapper<GradeFeedBack>().lambda()
                .eq(ObjectUtil.isNotNull(user.getId()),GradeFeedBack::getId,user.getId())
                .like(ObjectUtil.isNotEmpty(param.getCourseName()),GradeFeedBack::getCourseName,param.getCourseName())
                .eq(GradeFeedBack::getIsDelete,0)
                .eq(ObjectUtil.isNotEmpty(param.getCourseTime()),GradeFeedBack::getCourseTime,param.getCourseTime())
        );
        return gradeFeedback;
    }

    /*
     * @Description  修改分数回馈信息
     * @Param
     * @return
     **/

    public Outcome updateGradeFeedback(UpdateGradeFeedback feedback){
        UserInfo login = sysUserBusiness.getUserInfo();
//      UserInfo login =new UserInfo();
//      login.setId(4L);
        GradeCommentFeedback gcf = Convert.convert(GradeCommentFeedback.class,feedback);
        gcf.setUpdateBy(login.getId());
        Boolean update = gradeCommentFeedbackService.updateById(gcf);
        return Outcome.status(update);
    }
}
